/// <reference path="../typings/index.d.ts" />
/// <reference path="../src/carrierService.ts" />
/// <reference path="../src/tms.ts" />

describe('getCarrierList',() => {
    var injector:ng.auto.IInjectorService;
    var service:ICarrierService;

    beforeEach(() => {
        injector = angular.injector(['ng','tms']);
        service = injector.get<ICarrierService>('carrierService');
    });

    //常规无条件获取
    it('get carrier list normal',(done) => {
        service.getList(null, null, null, null,null,null,null,null,null, 0, 10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('|||||||||0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取排序字段枚举包含 1 的承运商列表
    it('get carrier list by orderBy \'1\'',(done) => {
        service.getList('1',null,null,null,null,null,null,null,null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('1|||||||||0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取升序的承运商列表
    it('get carrier list by asc \'true\' ',(done) => {
        service.getList(null,true,null,null,null,null,null,null,null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('|true||||||||0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取承运商名称包含 小程 的承运商列表
    it('get carrier list by name \'小程\'',(done) => {
        service.getList(null,null,'小程',null,null,null,null,null,null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('||小程|||||||0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });


    //获取承运商号码包含 7 的承运商列表
    it('get carrier list by phone \'7\' ',(done) =>{
        service.getList(null,null,null,'7',null,null,null,null,null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('|||7||||||0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取承运商类型包含 司机 的承运商列表
    it('get carrier list by type \'司机\' ',(done) =>{
        service.getList(null,null,null,null,'司机',null,null,null,null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('||||司机|||||0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取录入人包含 测试 的承运商列表
    it('get carrier list by inputperson \'测试\' ',(done) =>{
        service.getList(null,null,null,null,null,'测试',null,null,null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('|||||测试||||0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取承运商等级包含 VIP 的承运商列表
    it('get carrier list by level \'VIP\' ',(done) =>{
        service.getList(null,null,null,null,null,null,'VIP',null,null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('||||||VIP|||0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取主营路线包含 镇江 的承运商列表
    it('get carrier list by mainroute \'镇江\'',(done) =>{
        service.getList(null,null,null,null,null,null,null,'镇江',null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('|||||||镇江||0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    }); 

    //获取是否启用包含 禁用 的承运商列表
    it('get carrier list by isenabled \'false\'',(done) =>{
        service.getList(null,null,null,null,null,null,null,null,false,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('||||||||false|0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    }); 

    //获取排序字段枚举包含 1，升序，承运商名称包含小程，承运商号码包含 7 ，承运商类型包含 司机，录入人包含 测试，承运商等级包含 VIP，主营路线包含 镇江，禁用的承运商列表
    it('get carrier list by orderBy \'1\' and asc \'true\' and name \'小程\' and phone \'7\' and type \'司机\' and inputPerson \'测试\' and level \'VIP\' and mainRoute \'镇江\' and isEnabled \'false\' ',(done)=>{
        service.getList('1',true,'小程','7','司机','测试','VIP','镇江',false,0,10).then((res)=>{
            expect(res.data.total).toBe(10);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('1|true|小程|7|司机|测试|VIP|镇江|false|0|10');
            done();
        },(err)=>{
            done.fail(err);
        })
    })

    //获取承运商详情
    it('get detail',(done)=>{
        service.getDetail('3').then((res)=>{
            expect(res.data.name).toBe("detail");
            expect(res.data.type).toBe("司机");
            expect(res.data.phone).toBe("15854565852");
            expect(res.data.level).toBe("VIP");
            expect(res.data.address).toBe("镇江");
            expect(res.data.isEnabled).toBe(true);
            expect(res.data.remarks).toBe("备注");
            expect(res.data.AttachmentList[0].attachmentId).toBe('1');
            expect(res.data.AttachmentList[0].attachmentName).toBe('name2');
            expect(res.data.AttachmentList[0].attachmentPath).toBe('path2');
            expect(res.data.AttachmentList[0].attachmentTag).toBe('tag2');
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //添加承运商
    it('add carrier',(done)=>{
        service.add('笑笑','司机','18362822222','临时承运商','江苏','备注').then((res)=>{
            expect(res.data.extData).toBe("笑笑|司机|18362822222|临时承运商|江苏|备注");
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //编辑承运商
    it('edit carrier',(done)=>{
        service.edit('2','笑笑','司机','18362822233','临时承运商','江苏','备注2').then((res)=>{
            expect(res.data.extData).toBe("2|笑笑|18362822233|司机|临时承运商|江苏|备注2");
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //删除承运商
    it('delete carrier',(done)=>{
        service.delete('1').then((res)=>{
            expect(res.data.extData).toBe("1");
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //添加车辆和承运商的关系
    it('add carrierVehicleRelation',(done)=>{
        service.addCarrierVehicleRelation('苏L19988','1').then((res)=>{
            expect(res.data.extData).toBe("苏L19988|1");
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //删除车辆和承运商的关系
    it('delete carrierVehicleRelation',(done)=>{
        service.addCarrierVehicleRelation('苏L19980','1').then((res)=>{
            expect(res.data.extData).toBe("苏L19980|1");
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //修改启用状态
    it('ChangeEnable',(done)=>{
        service.enabled(true,'2').then((res)=>{
            expect(res.data.extData).toBe("true|2");
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //常规无条件获取承运商所属车辆列表
    it('get belongCarrierCar list normal',(done) => {
        service.getBelongCarrierCarList(null,0, 10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('|0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取 承运商编号包含3 的承运商所属车辆列表
    it('get belongCarrierCar list by id \'3\' ',(done)=>{
        service.getBelongCarrierCarList('3',0,10).then((res)=>{
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('3|0|10');
            done();
        },(err)=>{
            done.fail(err);
        });
    });


    //添加附件
    it('add attachment',(done)=>{
        service.addAttachment('2',[{attachmentId:'1',attachmentName:'name',attachmentPath:'path',attachmentTag:'tag'}]).then((res)=>{
            expect(res.data.extData).toBe("2|1|name|path|tag");
            done();
        },(err)=>{
            done.fail(err);
        });
    });

});